/*
 * GeneticInfoPanel.java
 *
 * Created on 24 kwiecień 2008, 11:03
 */

package flp.gui.view.annealing;

import flp.gui.view.genetic.*;
import flp.Layout;
import flp.solvers.annealing.AnnealingSettings;

/**
 * Klasa reprezentujaca panel obrazujacy dane liczbowe
 * dla algorytmu symulowanego wyrzazania.
 * 
 * @author Mateusz Pytel
 */
public class AnnealingInfoPanel extends javax.swing.JPanel {
      
    /**
     * Metoda inicjalizujaca nowy panel.
     */
    public AnnealingInfoPanel() {
        initComponents();
    }
    
    /**
     * Metoda ustawiajaca nowa wartosc tekstowa pola
     * z zegarem mierzacym czas trwania obliczen.
     * 
     * @param newText Nowy tekst dla etykiety.
     */
    public void setTimeLabelText(String newText){
        this.timerLabel.setText(newText);
    }
    
    /**
     * Konstruktor nowego panelu, przyjmuje dane bedace
     * ustawieniami algorytmu.
     * 
     * @param settings Ustawienia z jakimi pracuje algorytm wyzarzania.
     */
    public AnnealingInfoPanel(AnnealingSettings settings){
        this();
        maxTryCountValueLabel.setText("" + settings.getTries());
        maxConstIterValueLabel.setText("" + settings.getIterations());
        epsilonValueLabel.setText(String.format("%.2f", settings.getEpsilon()));
        annealingTypeValueLabel.setText(1 == settings.getCooling()
                ? "logarytmiczny"
                : "wykladniczy");
        
        resultLabel.setVisible(false);
        resultValueLabel.setVisible(false);

        tryProgressBar.setMinimum(0);
        tryProgressBar.setMaximum(settings.getTries());
        tryProgressBar.setStringPainted(true);
        tryProgressBar.setToolTipText("Pasek postępu dla wykonywanych prób");
    }
    
    /**
     * Metoda aktualizujaca etykiety panelu.
     * 
     * @param newTry Numer aktualnej proby.
     * @param newIter Numer aktualnej iteracji.
     * @param newTopCost Koszt dla aktualnej proby.
     * @param newTopGlobalCost Najlepszy aktualnie koszt globalny.
     * @param newTemperature Aktualna temperatura.
     */
    public void updateValues(int newTry, int newIter, int newTopCost, int newTopGlobalCost, double newTemperature){
       markOnBar(newTry);
       topCostValueLabel.setText(Integer.toString(newTopCost));
       topGlobalCostValueLabel.setText(Integer.toString(newTopGlobalCost));
       tempValueLabel.setText(String.format("%.2f", newTemperature));
    }
    
    /**
     * Metoda wywolywana po zakonczeniu obliczen dla danego przypadku
     * wyswietla dla niego rozwiazanie problemu.
     * 
     * @param bestLayout Najlepszy Layout znaleziony podczas optymalizacji.
     */
    public void showResult(Layout bestLayout){
       topCostLabel.setEnabled(false);
       topCostValueLabel.setEnabled(false);
       topGlobalCostLabel.setEnabled(false);
       topGlobalCostValueLabel.setEnabled(false);
       tempValueLabel.setEnabled(false);
       tempLabel.setEnabled(false);
       
       resultValueLabel.setText(""+bestLayout.toString2()+"    cost: "+topGlobalCostValueLabel.getText());
       resultLabel.setVisible(true);
       resultValueLabel.setVisible(true);
       resultValueLabel.setText(""+bestLayout.toString2()+"    cost: "+topGlobalCostValueLabel.getText());
       
    }
    
    /**
     * Metoda wypelniajaca pasek postepu na panelu.
     */
    public void fillBar(){
        tryProgressBar.setValue(tryProgressBar.getMaximum()+1);
        tryProgressBar.setString(tryProgressBar.getMaximum() + " / " + tryProgressBar.getMaximum());
    } 
    
    /**
     * Metoda zaznaczajaca postep na pasku postepu.
     * 
     * @param tryVal Wartosc do zaznaczenia.
     */
    private void markOnBar(int tryVal) {
        tryProgressBar.setValue(tryVal);
        tryProgressBar.setString(tryVal + " / " + maxTryCountValueLabel.getText());
    }
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        titleLabel = new javax.swing.JLabel();
        titlePrefixLabel = new javax.swing.JLabel();
        tryProgressBar = new javax.swing.JProgressBar();
        resultLabel = new javax.swing.JLabel();
        resultValueLabel = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        timerLabel = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        topCostLabel = new javax.swing.JLabel();
        topCostValueLabel = new javax.swing.JLabel();
        topGlobalCostValueLabel = new javax.swing.JLabel();
        topGlobalCostLabel = new javax.swing.JLabel();
        tempLabel = new javax.swing.JLabel();
        tempValueLabel = new javax.swing.JLabel();
        geneticSettingsPanel1 = new javax.swing.JPanel();
        maxConstIterValueLabel = new javax.swing.JLabel();
        maxConstIterLabel = new javax.swing.JLabel();
        maxSCIterLabel2 = new javax.swing.JLabel();
        epsilonValueLabel = new javax.swing.JLabel();
        maxIterLabel3 = new javax.swing.JLabel();
        maxTryCountValueLabel = new javax.swing.JLabel();
        annealingTypeLabel = new javax.swing.JLabel();
        annealingTypeValueLabel = new javax.swing.JLabel();

        titleLabel.setFont(new java.awt.Font("Tahoma", 1, 14));
        titleLabel.setForeground(new java.awt.Color(0, 102, 0));
        titleLabel.setText("SYMULOWANE WYŻARZANIE");

        titlePrefixLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        titlePrefixLabel.setText("Do optymalizacji zastosowano:");

        resultLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        resultLabel.setText("WYNIK:");

        resultValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        resultValueLabel.setForeground(new java.awt.Color(0, 0, 102));
        resultValueLabel.setText("przykladowy wynik");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel2.setForeground(new java.awt.Color(0, 0, 102));
        jLabel2.setText("Czas trwania obliczeń:");

        timerLabel.setFont(new java.awt.Font("Tahoma", 1, 12));
        timerLabel.setForeground(new java.awt.Color(0, 0, 102));
        timerLabel.setText("00:00");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Monitor wartości"));

        topCostLabel.setText("Najlepszy koszt dla próby:");

        topCostValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        topCostValueLabel.setText("0");

        topGlobalCostValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        topGlobalCostValueLabel.setText("0");

        topGlobalCostLabel.setText("Najlepszy koszt globalnie:");

        tempLabel.setText("Temperatura:");

        tempValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        tempValueLabel.setText("0");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(topCostLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(topCostValueLabel))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(topGlobalCostLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(topGlobalCostValueLabel))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(tempLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tempValueLabel)))
                .addContainerGap(106, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(topCostLabel)
                    .addComponent(topCostValueLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(topGlobalCostLabel)
                    .addComponent(topGlobalCostValueLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tempLabel)
                    .addComponent(tempValueLabel))
                .addContainerGap(31, Short.MAX_VALUE))
        );

        geneticSettingsPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Ustawienia algorytmu"));

        maxConstIterValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        maxConstIterValueLabel.setText("0");

        maxConstIterLabel.setText("Maksymalna ilość iteracji dla określonej temp.:");

        maxSCIterLabel2.setText("Dolna granica temperatury:");

        epsilonValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        epsilonValueLabel.setText("0");

        maxIterLabel3.setText("Ilość prób:");

        maxTryCountValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        maxTryCountValueLabel.setText("0");

        annealingTypeLabel.setText("Typ wyżarzania:");

        annealingTypeValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        annealingTypeValueLabel.setText("wykładniczy");

        javax.swing.GroupLayout geneticSettingsPanel1Layout = new javax.swing.GroupLayout(geneticSettingsPanel1);
        geneticSettingsPanel1.setLayout(geneticSettingsPanel1Layout);
        geneticSettingsPanel1Layout.setHorizontalGroup(
            geneticSettingsPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(geneticSettingsPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(geneticSettingsPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(geneticSettingsPanel1Layout.createSequentialGroup()
                        .addComponent(maxIterLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(maxTryCountValueLabel))
                    .addGroup(geneticSettingsPanel1Layout.createSequentialGroup()
                        .addComponent(maxConstIterLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(maxConstIterValueLabel))
                    .addGroup(geneticSettingsPanel1Layout.createSequentialGroup()
                        .addComponent(maxSCIterLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(epsilonValueLabel))
                    .addGroup(geneticSettingsPanel1Layout.createSequentialGroup()
                        .addComponent(annealingTypeLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(annealingTypeValueLabel)))
                .addContainerGap(78, Short.MAX_VALUE))
        );
        geneticSettingsPanel1Layout.setVerticalGroup(
            geneticSettingsPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(geneticSettingsPanel1Layout.createSequentialGroup()
                .addGroup(geneticSettingsPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(maxIterLabel3)
                    .addComponent(maxTryCountValueLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(geneticSettingsPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(maxConstIterLabel)
                    .addComponent(maxConstIterValueLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(geneticSettingsPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(maxSCIterLabel2)
                    .addComponent(epsilonValueLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(geneticSettingsPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(annealingTypeLabel)
                    .addComponent(annealingTypeValueLabel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tryProgressBar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 614, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(titlePrefixLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(titleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(timerLabel))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(geneticSettingsPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(resultLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(resultValueLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 566, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(timerLabel)
                        .addComponent(jLabel2))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(titlePrefixLabel)
                        .addComponent(titleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tryProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(geneticSettingsPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(resultLabel)
                    .addComponent(resultValueLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel annealingTypeLabel;
    private javax.swing.JLabel annealingTypeValueLabel;
    private javax.swing.JLabel epsilonValueLabel;
    private javax.swing.JPanel geneticSettingsPanel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JLabel maxConstIterLabel;
    private javax.swing.JLabel maxConstIterValueLabel;
    private javax.swing.JLabel maxIterLabel3;
    private javax.swing.JLabel maxSCIterLabel2;
    private javax.swing.JLabel maxTryCountValueLabel;
    private javax.swing.JLabel resultLabel;
    private javax.swing.JLabel resultValueLabel;
    private javax.swing.JLabel tempLabel;
    private javax.swing.JLabel tempValueLabel;
    private javax.swing.JLabel timerLabel;
    private javax.swing.JLabel titleLabel;
    private javax.swing.JLabel titlePrefixLabel;
    private javax.swing.JLabel topCostLabel;
    private javax.swing.JLabel topCostValueLabel;
    private javax.swing.JLabel topGlobalCostLabel;
    private javax.swing.JLabel topGlobalCostValueLabel;
    private javax.swing.JProgressBar tryProgressBar;
    // End of variables declaration//GEN-END:variables
    
}
